# Basic Python
import os
import math
import numpy as np
# Opening Geospatial Data
import geopandas as gpd
import rasterio as rio
import rioxarray as rxr
# Plotting
import hvplot.xarray
import hvplot.pandas
import holoviews as hv
# Other
import earthaccess
from modules.emit_tools import emit_xarray
from modules.ewt_calc import calc_ewtPython Environment tests
# Hard Coded File urls
emit_url = 'https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/EMITL2ARFL.001/EMIT_L2A_RFL_001_20230401T203751_2309114_002/EMIT_L2A_RFL_001_20230401T203751_2309114_002.nc'
ecostress_url = 'https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/ECO_L2T_LSTE.002/ECOv002_L2T_LSTE_26860_001_10SGD_20230401T203733_0710_01/ECOv002_L2T_LSTE_26860_001_10SGD_20230401T203733_0710_01_LST.tif'roi = gpd.read_file("../data/dangermond_boundary.geojson")# Sign into EDL and get token
token = earthaccess.login(persist=True).token['access_token']# Download EMIT Scene
# Get requests https Session using Earthdata Login Info
fs = earthaccess.get_requests_https_session()
# Retrieve granule asset ID from URL (to maintain existing naming convention)
granule_asset_id = emit_url.split('/')[-1]
# Define Local Filepath
fp = f'../data/{granule_asset_id}'
# Download the Granule Asset if it doesn't exist
if not os.path.isfile(fp):
with fs.get(emit_url,stream=True) as src:
with open(fp,'wb') as dst:
for chunk in src.iter_content(chunk_size=64*1024*1024):
dst.write(chunk)Test EMIT tools reading and ortho
# Open EMIT and Orthorectify
emit_ds = emit_xarray(fp, ortho=True)Geoviews Tiles, Image, and Polygon Plotting
# Geoviews + Polygon Visualizations
emit_ds['reflectance'].data[emit_ds['reflectance'].data == -9999] = np.nan
size_opts = dict(frame_height=405, frame_width=720, fontscale=2)
map_opts = dict(geo=True, crs='EPSG:4326', alpha=0.7, xlabel='Longitude',ylabel='Latitude')
emit_ds.sel(wavelengths=850, method='nearest').hvplot.image(cmap='viridis',tiles='ESRI',**size_opts, **map_opts)*roi.hvplot(color='#d95f02',alpha=0.5, crs='EPSG:4326')